import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { SpecialGiftInfo } from "../../../model/SpecialGiftInfo";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { BrowerUtil } from "../../../../../com/gengine/utils/BrowerUtil";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ObjCreate } from "../../common/ObjCreate";
type int = number;
//class SpecialGiftGetWindow
    
    export  class SpecialGiftGetWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            if (SpecialGiftGetWindow._instance) 
            {
                throw new Error("SpecialGiftGetWindow is single!");
            }
            SpecialGiftGetWindow._instance = this;
            setSize(250, 155);
            title = Language.getString(35800);
            titleHeight = 30;
            return;
        }

        public updateData(arg1: SpecialGiftInfo): void
        {
            this._info = arg1;
            if (this._info.giftFlagUrl) 
            {
                this._getCardTxt.visible = true;
            }
            else 
            {
                this._getCardTxt.visible = false;
            }
            return;
        }

        /* internal  */onSureBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._cardText.text;
            if (!(loc1 == "") && this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SpecialGiftGetReq, {"code": this._info.code, "key": loc1}));
            }
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */onGetCardLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._info && this._info.giftFlagUrl) 
            {
                BrowerUtil.getUrl(this._info.giftFlagUrl);
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            super.createChildren();
            loc1 = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            loc1.x = 17;
            loc1.y = 40;
            loc1.setSize(217, 105);
            addChild(loc1);
            var loc2=new Object /* flash.text.TextField */();
            loc2.x = 70;
            loc2.y = 48;
            loc2.width = 150;
            loc2.height = 20;
            loc2.selectable = false;
            loc2.text = Language.getString(35801);
            loc2.setTextFormat(GlobalStyle.textFormat1);
            addChild(loc2);
            this._cardText = new GTextInput();
            this._cardText.setSize(190, 20);
            this._cardText.styleName = "GTextInput";
            this._cardText.restrict = "a-zA-Z0-9";
            this._cardText.move(30, 70);
            addChild(this._cardText);
            var loc3=new GButton();
            loc3.styleName = "Button";
            loc3.label = Language.getString(69901);
            loc3.setSize(60, 25);
            loc3.move(50, 95);
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onSureBtnClickHandler);
            addChild(loc3);
            var loc4;
            (loc4 = new GButton()).styleName = "Button";
            loc4.label = Language.getString(69902);
            loc4.setSize(60, 25);
            loc4.move(140, 95);
            loc4.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            addChild(loc4);
            this._getCardTxt = ObjCreate.createTextField("", 35, 125, 200, 20, this, GlobalStyle.textFormat5);
            this._getCardTxt.htmlText = "<a href=\'event: 0\'><u>" + Language.getString(35802) + "</u></a>";
            this._getCardTxt.addEventListener(flash.events.TextEvent.LINK, this.onGetCardLinkHandler);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show();
            this._cardText.text = "";
            return;
        }

        public static get instance(): SpecialGiftGetWindow
        {
            if (!SpecialGiftGetWindow._instance) 
            {
                SpecialGiftGetWindow._instance = new SpecialGiftGetWindow();
            }
            return SpecialGiftGetWindow._instance;
        }

        /* internal */ /* var */_cardText: GTextInput;

        /* internal */ /* var */_getCardTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_info: SpecialGiftInfo;

        /* internal */ static /* var */_instance: SpecialGiftGetWindow;
    }
